import Request from './initRequest'
import type { RequestConfig } from './types'

const baseRequest = new Request({
	// baseURL: 'https://www.op.gg',
	timeout: 1000 * 60 * 5,
})

interface myRequestConfig<T> extends RequestConfig {
	data?: T
}
interface myResponseConfig<T> {
	code: number
	message: string
	data: T
}

/**
 * @description: 函数的描述
 * @interface D 请求参数的interface
 * @interface T 响应结构的intercept
 * @param {myRequestConfig} config 不管是GET还是POST请求都使用data
 * @returns {Promise}
 */
const request = <D, T = any>(config: myRequestConfig<D>): Promise<any> => {
	const { method = 'GET' } = config
	if (method === 'get' || method === 'GET') {
		config.params = config.data
	}
	return baseRequest.request<myResponseConfig<T>>(config)
}

export default request
